<?php
class User extends AppModel {

	public $name = 'User';
    public $displayField = 'email';
    public $validate     = array(
        'email' => array(
            'rule'    => array('email', true),
            'message' => 'Please supply a valid email address'
        ),
        'password' => array(
            'minlength' => array(
                'rule'    => array('minLength', 6),
                'message' => 'Password must be at least 6 characters long'
            ),
            'maxlength' => array(
                'rule'    => array('maxLength', 40),
                'message' => 'Password must be no larger than 40 characters long'
            )
        ),
        'nickname' => array(
            'rule'       => array('between', 3, 20),
            'allowEmpty' => true,
            'message'    => 'Nickname must be between 3 and 20 characters long'
        )
    );
    public $hasMany      = array(
        'AdPost' => array(
            'limit'      => 5,
            'conditions' => 'AdPost.active = 1',
            'order'      => 'AdPost.created DESC',
            'dependent'  => true
        )
    );


    public function isEmailTaken ($email) {
        return $this->find('count', array('conditions'=>array('User.email'=>$email), 'recursive'=>-1));
    } // isEmailTaken

} // User
?>